package com.yycx.dbr.boot.admin.test.thread;

import com.yycx.module.admin.client.entity.BaseUser;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;

/**
 * Callable 支持有返回值的多线程
 *
 * @author 汪兴安
 */
public class DemoThread implements Callable<List<BaseUser>>  {
    private final int pageIndex;

    /**
     * 通过构造器，初始化
     *
     * @param pageIndex
     */
    public DemoThread(int pageIndex) {
        this.pageIndex = pageIndex;
    }

    @Override
    public List<BaseUser> call() throws Exception {
        //模拟每个线程执行耗时不一样
        if (pageIndex % 2 == 0) {
            Thread.sleep(5000);
        } else {
            Thread.sleep(2000);
        }

        System.out.println("查询第" + pageIndex + "页");
        List<BaseUser> list = new ArrayList();

        /**
         * 模拟查询的数据对象
         */
        BaseUser user = new BaseUser();
        user.setNickName("userId" + pageIndex);
        user.setUserName("张三" + pageIndex);

        list.add(user);
        return list;
    }



}
